Skip to content

Fix Lua GC leak: eagerly release C++ refs via tracking lists#90

Draft
mfazekas wants to merge 1 commit intorive-app:mainfrom
mfazekas:fix/lua-gc-releaseall
Draft

Fix Lua GC leak: eagerly release C++ refs via tracking lists#90
mfazekas wants to merge 1 commit intorive-app:mainfrom
mfazekas:fix/lua-gc-releaseall

Conversation

@mfazekas
Copy link
Copy Markdown

Lua userdata (ScriptedArtboard, ScriptedViewModel) hold rcp<> refs to C++ objects (DataContext, ViewModelInstance, File) and are stored in the Lua registry as independent GC roots via lua_ref(). When a parent artboard is destroyed, only m_self and m_context are unreffed — but m_dataRef, m_propertyRefs, and m_valueRef remain rooted in the registry, keeping all referenced C++ objects alive permanently. Fix by tracking instances in linked lists and eagerly nullifying their C++ refs before GC.

@mfazekas mfazekas changed the title Fix Lua GC reentrancy leak: eagerly release C++ refs via tracking lists Fix Lua GC leak: eagerly release C++ refs via tracking lists Mar 25, 2026
Sub-artboard scripts store m_context, m_dataRef, m_propertyRefs as
independent registry refs via lua_ref(). When the parent artboard is
destroyed, only top-level scripts' refs are unreffed — the sub-artboard
refs remain as GC roots, keeping C++ objects alive permanently. Track
ScriptReffedArtboard and ScriptedViewModel instances in linked lists
and null their C++ rcp<> pointers during artboard destruction.
@mfazekas mfazekas force-pushed the fix/lua-gc-releaseall branch from e4651cc to 90cbe04 Compare March 25, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant